package com.wu.wechat.util;


import com.wu.common.utils.JsonUtils;
import com.wu.entity.sys.ProjectErrorConfig;
import com.wu.entity.sys.UserPhone;
import com.wu.entity.weixin.po.WeixinGzuserinfo;
import com.wu.wechat.service.SystemActTxtService;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;

public class DataDictTool {
    private static SystemActTxtService systemActTxtService;

    public DataDictTool() {
    }

    public int getProductRateNum(int num, int rate) {
        int count = num * rate;
        return count;
    }

    public boolean isLteZero(BigDecimal productNewPrice) {
        boolean flag = false;
        if (productNewPrice != null && productNewPrice.compareTo(BigDecimal.ZERO) <= 0) {
            flag = true;
        }

        return flag;
    }

    public String subText(String text, int length, String endWith) {
        return JsonUtils.subString(text, length, endWith);
    }

    public String priceNoZero(BigDecimal price) {
        String priceStr = "";
        if (price != null) {
            priceStr = price.toString();
            priceStr = priceStr.replaceAll("0+$", "");
            priceStr = priceStr.replaceAll("[.]$", "");
        }

        return priceStr;
    }

    public String getSysText(String code, String actCode) {
        String text = systemActTxtService.queryActTxtByCode(code, actCode);
        return StringUtils.isEmpty(text) ? "" : text;
    }

    public ProjectErrorConfig getSysErrorConfig(String projectPath) {
        ProjectErrorConfig config = systemActTxtService.getSysErrorConfig(projectPath);
        return config;
    }

    public String escapeHtml(String html) {
        try {
            html = StringEscapeUtils.escapeHtml(html);
            return html;
        } catch (Exception var3) {
            return "";
        }
    }

    public String unescapeHtml(String html) {
        try {
            html = StringEscapeUtils.unescapeHtml(html);
            return html;
        } catch (Exception var3) {
            return "";
        }
    }

    public UserPhone getUserPhoneByOpenid(String openid) {
        return systemActTxtService.getUserPhoneByOpenid(openid);
    }

    public WeixinGzuserinfo getWeixinGzuserinfo(String openid) {
        return systemActTxtService.getUserInfo(openid);
    }

    public static void setSystemActTxtService(SystemActTxtService systemActTxtService) {
        DataDictTool.systemActTxtService = systemActTxtService;
    }

    public static void main(String[] args) {
        DataDictTool tool = new DataDictTool();
        String html = "<div name=\"searchColums\"></div>";
        html = tool.escapeHtml(html);
        System.out.println(html);
        html = tool.unescapeHtml(html);
        System.out.println(html);
    }
}

